package com.vcar.LDiceClient.command
{
	import com.vcar.LDiceClient.command.handler.SocketDataHandler;
	import com.vcar.LDiceClient.config.GlobalEventName;
	import com.vcar.LDiceClient.dataproxy.ResponseMessage;
	
	import mx.controls.Alert;
	import mx.logging.ILogger;
	import mx.logging.Log;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	/**
	 * 处理socket接收到的数据
	 * @author rhj
	 *
	 */
	public class SocketDataCommand extends SimpleCommand
	{
		
		private static var log:ILogger = Log.getLogger("com.vcar.LDiceClient.command.SocketDataCommand");
		
		public function SocketDataCommand()
		{
			super();
		}
		
		override public function execute(notification:INotification):void
		{
			var data:ResponseMessage=notification.getBody() as ResponseMessage;
			if (!data && !data.type) //这里的作用是检测是否resopnseMessage类型
			{
				return;
			}
			
			//debug
			log.debug("收到服务器信息"+data.type+","+data.subtype+" user="+(facade as ApplicationFacade).getCurrentUser().username);

			switch (data.type)
			{
				case 1:
					switch(data.subtype)
					{
						case 1://得到服务器时间
							SocketDataHandler.onGetServerTime(data);
							break;
					}
					break;
				case 2:
					switch(data.subtype)
					{
//						2,1[账号]登录游戏
						case 1:
							if(data.succ){
								SocketDataHandler.loginSuccHandle(data);
							}
							else
							{
								Alert.show(data.object.msg.toString());
							}
							break;
//						2,2[账号]退出游戏
						case 2:
							SocketDataHandler.loginFail(data);
							break;
//						2,3[账号]注册
//						2,4[账号][角色]列表
//						2,5创建[角色]
//						2,6删除[角色]

					}
					
					break;
				case 3:
					sendNotification(GlobalEventName.CHAT_MSG_GET, data);
					break;
				case 4:
					switch(data.subtype)
					{
//						4,1	[账号]详细信息
//						4,2	[角色]详细信息
//						4,3	[房间]详细信息					
					}
					break;
				case 5:
					switch(data.subtype)
					{
						case 1:
							//sendNotification(GlobalEventName.STORE_GETLIST_SUSS, data);
							break;
						case 2:
							sendNotification(GlobalEventName.STORE_GETLIST_SUSS, data);
							break;
					}
					break;
				case 6:
					switch(data.subtype)
					{
						case 2: //6,2   获取店铺信息
							if(data.succ){
								sendNotification(GlobalEventName.STORE_GETDATA_SUSS,data)	
							}
						case 3: //6,3	进入[店铺]
							if(data.succ){
								sendNotification(GlobalEventName.STORE_JOIN_SUSS,data);
							}
							break;
						case 4: //6,4	离开[店铺]
							if(data.succ){
								sendNotification(GlobalEventName.STORE_EXIT_SUSS,data);
							}
							break;


					}
					break;
				case 7:
					switch(data.subtype)
					{
						//7,1	开始[战斗]
						case 2://7,2	坐下
							if(data.succ){
								sendNotification(GlobalEventName.STORE_SITDOWN_SUSS,data)
							}
							break;
						
						case 3:
							if(data.succ){
								sendNotification(GlobalEventName.STORE_STANDUP_SUSS,data)
							}
							break;
						case 4:
							if(data.succ){
								sendNotification(GlobalEventName.GAME_READY_SUSS,data)
							}
							break;
						
						case 5: //7,5   物品拿起
							if(data.succ){
								sendNotification(GlobalEventName.STORE_ITEMPICKUP_SUSS,data)	
							}						
							break;
						
						case 6: //7,6	物品放下
							if(data.succ){
								sendNotification(GlobalEventName.STORE_ITEMPICKDOWN_SUSS,data);
							}
							break;
					}
					break;
				case 8:
					switch(data.subtype)
					{
						case 1://8,1 游戏开始
							if(data.succ){
								sendNotification(GlobalEventName.GAME_BEGIN_SUSS,data)	
							}						
							break;
						case 2://8,2游戏结束
							if(data.succ){
								sendNotification(GlobalEventName.GAME_END_SUSS,data)	
							}						
							break;
						
						case 7: //8,7	进入游戏
							if(data.succ){
								sendNotification(GlobalEventName.GAME_ENTER_SUSS,data);
							}
							break;
						case 8: //8,7	进入游戏
							if(data.succ){
					 			sendNotification(GlobalEventName.GAME_CALLDICE_SUSS,data);
							}
							break;
						case 9: //8,7	进入游戏
							if(data.succ){
								sendNotification(GlobalEventName.GAME_OPEN_SUSS,data);
							}
							break;
					}
					break;


			}
		}
	}
}